﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;


namespace SF.Web.UI.mallCs
{
    public class address
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "syj")
                {
                    usingMsg = "<link href='css/user.css' rel='stylesheet' />";
                }
                else if (templateType == "weishanggreen")
                {
                    usingMsg = "<link href='css/user.css' rel='stylesheet' />";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    jsMsg = "$(document).ready(function () {for (var i = 0; i < $('.moren').length ; i++) {var isd = $($('.moren')[i]).attr('isdefault');if (isd >= 1) {$($('.moren')[i]).text('默认');}}});function del(id) {if (confirm('确认删除?')) {$.get('/tools/user_ajax.ashx', { action: 'delete_address', id: id }, function (rs) {if (rs=='0') {window.location.reload();} else {alert('删除失败，刷新页面!');}});}}function setDefault(id) {if (confirm('设置为默认地址?')) {$.get('/tools/user_ajax.ashx', { action: 'check_address', id: id, orderNum: $('#header').attr('orderId') }, function (rs) {if (rs=='0') {if ($('#header').attr('orderId') != '' && $('#header').attr('orderId') != null) {window.location = 'orderdetail.aspx?orderId=' + $('#header').attr('orderId');} else {window.location.reload();}} else {alert('设置失败，刷新页面!');}});}}";
                }
            }
            return jsMsg;
        }
        public string loaddingHtml(Model.sf_user_info userInfo, string parm1, string templateType)
        {
            string htmlMsg = "",appWhere="";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    string addressMsg = "";
                    appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                    BLL.sf_user_address bll = new BLL.sf_user_address();
                    BLL.sf_goods_order orderBll = new BLL.sf_goods_order();
                    DataTable dt = bll.GetList(" userNum='" + userInfo.userNum + "' and " + appWhere).Tables[0];
                    foreach (DataRow row in dt.Rows)
                    {
                        addressMsg += "<div class='u-addrbox userdiv'><div class='addr_box'><p>客户姓名：" + row["personName"] + "<span class='addr_tel'>联系电话：" + row["phone"] + "</span></p><p class='clear'></p><p>详细住址：" + row["detailAddress"] + "</p><span class='moren' style='display: block;' isdefault='" + row["isDefault"] + "' ></span></div><div class='addr_ope'><a href='javascript:;' onclick='setDefault(" + row["id"] + ");'><span class='edi'></span>默认</a><a href='javascript:;' onclick='del(" + row["id"] + ");'><span class='delete'></span>删除</a></div></div>";
                    }
                    htmlMsg = "<body><form id='form1' runat='server'><header id='header' class='u-header clearfix' orderId='" + parm1 + "'><div class='u-hd-left f-left'><a href='javascript:history.back();' class='J_backToPrev'><span class='u-icon-px i-hd-back'></span></a></div><div class='u-hd-tit'><span>地址列表</span></div><div class='u-hd-right f-right'><a href='user.aspx'><span class='u-icon-px i-hd-home'></span></a></div></header><a href='newAddress.aspx?orderId=" + parm1 + "' data-addaddress='true' class='textlink fl' >新增收货地址+</a><div class='clear'></div>" + addressMsg + "<div class='u-footer clearfix'></div><a href='#top' class='u-backtop'><span class='u-icon-px i-backtop'></span></a></form></body>";
                }
            }
            return htmlMsg;
        }
    }
}
